package com.yinhe.music.yhmusic.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.constants.IConstants;
import com.yinhe.music.yhmusic.db.DataBaseAccessor;
import com.yinhe.music.yhmusic.downmusic.DownloadStatus;
import com.yinhe.music.yhmusic.model.Music;
import com.yinhe.music.yhmusic.widget.SmoothCheckBox;

import java.util.List;

/**
 * Created by hasee on 2017/8/15.
 */

public class MusicManagerAdapter extends BaseQuickAdapter<Music, BaseViewHolder> {

    public MusicManagerAdapter(@Nullable List<Music> data) {
        super(R.layout.select_item, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final Music item) {
        final SmoothCheckBox cb = helper.getView(R.id.scb);
        cb.setOnCheckedChangeListener((checkBox, isChecked) ->
            item.setChecked(isChecked)
        );
        cb.setChecked(item.isChecked());
//        if (item.getQualityLevel() != null) {
//            switch (item.getQualityLevel()) {
//                case IConstants.Common:
//                    helper.setImageResource(R.id.img, R.drawable.ic_regular);
//                    break;
//                case IConstants.HQ:
//                    helper.setImageResource(R.id.img, R.drawable.ic_hq);
//                    break;
//                case IConstants.SQ:
//                    helper.setImageResource(R.id.img, R.drawable.ic_sq);
//                    break;
//            }
//        } else {
//            helper.setVisible(R.id.img, false);
//        }

        helper.itemView.setOnClickListener((v) -> {
            item.setChecked(!item.isChecked());
            cb.setChecked(item.isChecked(), true);
        });

        if (DataBaseAccessor.getInstance().isExsitIdSyn(item.getSongId(),
                DownloadStatus.DOWNLOAD_STATUS_COMPLETED)) {
            helper.setGone(R.id.image_get, true);
        } else {
            helper.setGone(R.id.image_get, false);
        }

        helper.setText(R.id.tv, item.getSongName());
    }
}
